<?php
/*
 * coding: utf-8
 * +-------------------------------------------------------------------
 * | KL库 - SESSION模块
 * +-------------------------------------------------------------------
 * | Copyright (c) 2022-2099 KL库(https://www.fangheyun.xyz) All rights reserved.
 * +-------------------------------------------------------------------
 * | Author: 远易 <3431628590@qq.com>
 * +-------------------------------------------------------------------
 */

if(SESSION_SWITCH){
    class SESSION {
        /**
         * 开启 session
         */
        public function start(){
            return session_start();
        }
        /**
         * 创建 session
         */
        public function create($key='', $value=''){
            if($key == ''){
                exit("ERROR: Key cannot be empty");
            }
            if($value == ''){
                exit("ERROR: Value cannot be empty");
            }
            return $_SESSION[$key] = $value;
        }
        /**
         * 读取 session
         */
        public function session($key=''){
            if(isset($_SESSION[$key]))
            {
                return $_SESSION[$key];
            }else{
                return NULL;
            }
        }
        /**
         * 判断 session 是否存在
         */
        public function is_session($key=''){
            if(isset($_SESSION[$key]))
            {
                return True;
            }else{
                return False;
            }
        }
        /**
         * 销毁 session
         */
        public function unset($key=''){
            if($key == ''){
                exit("ERROR: Key cannot be empty");
            }
            if(isset($_SESSION[$key]))
            {
                unset($_SESSION[$key]);
                return True;
            }else{
                return False;
            }
        }
        /**
         * 销毁所有 session
         */
        public function destroy(){
            return session_destroy();
        }
	}
}
?>